/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package requeteur;

import java.util.ArrayList;
import java.util.HashMap;
import model.Terme;

/**
 *
 * @author Nargisse
 */
public class ParagCollection {
    private HashMap<Integer,Paragraphe> map;
    
    
    public ParagCollection(){
        this.map = new HashMap<Integer,Paragraphe>();
    }
    
    /*public void addParagraphe(int para, double poids){  
        Paragraphe p;
        if(!map.containsKey(para)){
            map.put(para, new Paragraphe(para, poids));
        }else{
            p = map.get(para);
            p.addPoids(poids);
        }  
    }*/
    
    public void addParagrapheList(ArrayList<Paragraphe> lp){
        Paragraphe pp;
        for(Paragraphe p : lp){
            if(!map.containsKey(p.getIdParagraphe())){
                map.put(p.getIdParagraphe(), p);
            }else{
                double poidsExistant = this.getPoidsParaFromHM(p.getIdParagraphe());
                if(poidsExistant != p.getPoidsParag()){
                    pp = new Paragraphe(p.getIdParagraphe(), poidsExistant+p.getPoidsParag());
                }else{
                    pp = new Paragraphe(p.getIdParagraphe(), poidsExistant);
                }
                map.put(p.getIdParagraphe(), pp);
            }
        }
        
        
    }
    
    public double getPoidsParaFromHM(int parag){
        Paragraphe pp = map.get(parag);
        return pp.getPoidsParag();
    }
    
    public ArrayList<Paragraphe> getListParagraphes(){
        ArrayList<Paragraphe> res = new ArrayList<Paragraphe>();
        for(Paragraphe p : this.map.values()){
            res.add(p);
        }
        return res;
    }
    
   
}
